package net.fivegoods.web;

import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import net.fivegoods.entity.impl.slim3.MissionClientModel;

import org.slim3.datastore.Datastore;

@Path("/clients")
public class MissionClients {
    
    @GET
    @Path("/{key}")
    public MissionClientModel get(@PathParam("key") String encodedKey) {
        return MissionClientModel.getByKeyString(encodedKey);
    }
    @POST
    public MissionClientModel create(
            @FormParam("name") String name,
            @FormParam("address") String address,
            @FormParam("tel") String tel,
            @FormParam("fax") String fax,
            @FormParam("mailAddress") String mailAddress,
            @FormParam("url") String url,
            @FormParam("prefecture") int prefecture) {
        MissionClientModel client = new MissionClientModel();
        client.setName(name);
        client.setAddress(address);
        client.setTel(tel);
        client.setFax(fax);
        client.setMailAddress(mailAddress);
        client.setUrl(url);
        client.setPrefecture(prefecture);
        
        client.save();
        return client;
    }
    @PUT
    public MissionClientModel update(@FormParam("key") String encodedKey) {
        MissionClientModel client = MissionClientModel.getByKeyString(encodedKey);
        client.setKey(Datastore.stringToKey(encodedKey));
        client.save();
        return client;
    }
    @DELETE
    @Path("/{key}")
    public void delete(@PathParam("key") String encodedKey) {
        MissionClientModel.deleteByKeyString(encodedKey);
    }
}
